
<template>
	<div class="index">

		<div class="center">
			<left></left>
			<div class="right">
          <top></top>
          <div class="hei10"></div>

		  <div class="where" style="background: #fff; padding: 10px 30px; font-size: 14px; color: #595959;">
		    当前位置：
		    <router-link to="/index" style="color: #409eff;">分销后台</router-link>>
		    <router-link to="/order_question" style="color: #409eff;">订单处理</router-link>>
		    刷单订单设置
		  </div>

		  <div class="hei10"></div>

        <div class="title">刷单订单设置</div>
        <div style="justify-content: space-between; display: flex;">
          <div style="padding: 20px;">
            <el-input v-model="source2" size="medium" style="width: 200px;"  placeholder="请输入渠道名"></el-input>
            <el-button type="danger" size="medium" @click="search2">搜索</el-button>
          </div>
          <div class="add">
            <el-button type="danger"  size="medium" @click="xinzeng">增加刷单店铺</el-button>
          </div>
        </div>


        <div class="con" v-loading="loading">
          <div class="list">
            <div class="th">店铺名称</div>
            <div class="th">商品名称</div>
            <div class="th">商品编码</div>
            <div class="th" style="flex: 2;">设置拦截时间周期</div>
            <div class="th">拦截开关</div>
            <div class="th">操作</div>
          </div>
          <div class="list" v-for="item in list" :key="item.id">
            <div class="td">{{item.source}}</div>
            <div class="td">{{item.title}}</div>
            <div class="td">{{item.fetch_code}}</div>
            <div class="td" style="flex: 2;">
              <div v-if="item.durations !=''">
                <el-tag v-for="tag in item.durations" :key="tag.id" closable  @close="del(tag.id)" style="margin: 0 5px;">
                  {{tag.start}}-{{tag.end}}
                </el-tag>
                <el-button size="mini" type="primary" style="margin-left: 20px;" @click="addtime(item.id)">添加周期</el-button>
              </div>
              <div v-if="item.durations ==''">未添加全天拦截<el-button size="mini" type="primary" style="margin-left: 20px;" @click="addtime(item.id)">添加周期</el-button></div>
            </div>
            <div class="td" ><el-switch v-model="item.status" @change="kaiguan(item.id,item.status)" active-color="#13ce66" inactive-color="#ff4949"></el-switch></div>

            <div class="td">
              <el-button type="text" size="mini" @click="tiaozhuan(item.id)">删除</el-button>
            </div>
          </div>
          <el-pagination background layout="total,prev, pager, next" :current-page="page" @current-change="fanye"
            :page-size="pagesize" :total="total"></el-pagination>
        </div>
      </div>
    </div>
    <el-dialog title="增加刷单店铺" :visible.sync="log" width="500px" :close-on-click-modal="false">
      <div style="margin-bottom: 20px;">
        <el-select v-model="all.source" @change="morenxuanzhong" clearable placeholder="请选择店铺" style="margin-bottom: 10px; width: 100%;">
          <el-option v-for="item in dianpulist" :key="item.id" :label="item.source +'-'+ item.shop_name" :value="item.source +'-'+ item.shop_name"></el-option>
        </el-select>
      </div>
      <div class="kflexc" style="margin-bottom: 20px;">
        <el-radio v-model="all.product_block_type" label="2" @change="lanjiexuan">全部商品拦截</el-radio>
        <el-radio v-model="all.product_block_type" label="1" @change="lanjiexuan">指定商品拦截</el-radio>
      </div>
      <div style="margin-bottom: 20px;" v-if="all.product_block_type == 1">

        <el-select v-model="all.page_id"  :reserve-keyword="true" clearable multiple collapse-tags filterable	placeholder="商品编码/商品名称">
        	<el-option v-for="item in allprolist2" :key="item.id" :label="item.fetch_code + '_' + item.title"
        		:value="item.id"></el-option>
        </el-select>

        <!-- <el-input  style="margin-bottom: 10px;" v-model.trim="fetch_code" @input="search" placeholder="请输入商品编码"></el-input> -->
        <div class="result">{{result}}</div>
      </div>
      <div class="kflexc" style="margin-bottom: 20px;">
        <el-checkbox :true-label="1" :false-label="0"  v-model="all.address_detail_by_number">按照详细地址包含数字识别刷单</el-checkbox>
        <el-tooltip placement="top">
          <div slot="content">
            当详细地址中出现≥7位的连续数字且不是11位，</br>
            则判定为刷单订单，您可与刷手约定，</br>
            随机填写超过7位的连续数字即可
          </div>
          <i class="el-icon-question" style="color:#979797; font-size: 18px;"></i>
        </el-tooltip>
      </div>
      <div class="kflexc" v-if="all.source && (all.source.startsWith('ks') || all.source.startsWith('douyin'))" style="margin-bottom: 20px;"><el-checkbox :true-label="1" :false-label="0"  v-model="all.is_auto_approved">识别为刷单后自动审核通过，电商后台进入待发货</el-checkbox></div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="log = false" round>取消</el-button>
        <el-button type="danger" @click="loggo" round>确定添加</el-button>
      </span>
    </el-dialog>
    <el-dialog title="增加拦截时间" :visible.sync="lanjielog" width="440px" :close-on-click-modal="false">
      <div style="line-height: 28px;">
        <el-time-picker v-model="start" size="medium" value-format="HH:mm:ss" style="margin-bottom: 20px;" placeholder="选择开始时间"></el-time-picker>
        <el-time-picker v-model="end" size="medium" value-format="HH:mm:ss" placeholder="选择结束时间"></el-time-picker>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="lanjielog = false">取消</el-button>
        <el-button type="primary" @click="lanjiego">确定添加</el-button>
      </span>
    </el-dialog>
    <!-- <foot></foot> -->
    <notice></notice>
  </div>
</template>
<script>
  import axios from 'axios'
  import top from '@/components/top.vue'
  import left from '@/components/left.vue'
  import foot from '@/components/foot.vue'
  import notice from '@/components/notice.vue'
  export default {
    components: {
      "left": left,
      "top": top,
      "foot": foot,
      "notice": notice
    },
    name: 'mySupplier',
    data() {
      return {
        all:{
          source:"",
          page_id:"",
          product_block_type:"",//商品拦截类型:1=指定商品拦截,2=全部商品拦截
          is_auto_approved:0,//自动审核:0=否,1=是
          address_detail_by_number:"",//详细地址按照数字识别:0=否,1=是
          id:""
        },
        lanjielog:false,
        msg: "hello",
        loading: true,
        log: false,
        disid: "",
        result: "",
        list: "",
        total: 0,
        pagesize: 20,
        page: 1,
        dianpulist:[],
        source:"",
        page_id:"",
        fetch_code:"",
        start:"",
        end:"",
        lanjieid:"",
        source2:"",
        allprolist2:[]
      }
    },
    created() {

      //获取所有产品
      axios.get("/api/gth/order-pages?_page_size=5000&equal=1")
      	.then(response=> {
      		if (response.data.msg.code == 0) {
      			this.allprolist2 = response.data.data.data
      		}
      	})

      this.getlist();
      this.getdianpu()
    },
    methods: {
      morenxuanzhong:function(){
        if(this.all.source && (this.all.source.startsWith('ks') || this.all.source.startsWith('douyin'))){
          this.all.is_auto_approved = 1
        }else{
          this.all.is_auto_approved = 0
        }
      },
      xinzeng:function(){
        this.all = {
          source:"",
          page_id:"",
          product_block_type:"",//商品拦截类型:1=指定商品拦截,2=全部商品拦截
          is_auto_approved:"",//自动审核:0=否,1=是
          address_detail_by_number:"",//详细地址按照数字识别:0=否,1=是
          id:""
        }
        this.log = true
      },
      lanjiexuan:function(){
        this.fetch_code = ""
        this.result = ""
        this.all.page_id = []
      },
      search2:function(){
        this.page = 1
        this.getlist()
      },
      del:function(id){
        let data = {}
        data.id = id
        axios.post('/api/plan-market/shuadan/duration/delete', data)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('删除成功');
              this.getlist();
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      addtime:function(id){
        this.lanjieid = id
        this.lanjielog = true
      },
      lanjiego:function(){
        let data = {}
        let start
        let end
        data.task_id = this.lanjieid
        if(this.start == '' || this.end == ''){
          this.$message.error("必须选择时间！");
          return false
        }else{
          data.start = this.start
          data.end = this.end
        }
        axios.post('/api/plan-market/shuadan/duration/config', data)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('添加周期成功');
              this.getlist();
              this.lanjielog = false
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //开关
      kaiguan:function(id,status){
        console.log(status)
        let data = {}
        data.id = id
        if(status == true){
          data.status = 1
        }
        if(status == false){
          data.status = 0
        }
        axios.post('/api/plan-market/shuadan/page/status', data)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('修改成功');
              this.getlist();
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      getdianpu:function(){
        //获取号码
        axios.get('/api/gth/out-store/list')
        .then(response => {
          if(response.data.msg.code == 0){
              this.dianpulist = response.data.data
        	}else{
        			this.$message.error(response.data.msg.info);
        	}
        })

      },
      //翻页
      fanye: function(page) {
        this.loading = true
        this.page = page
        this.getlist()
      },
      //跳转
      tiaozhuan: function(id) {
        let data = {}
        data.id = id
        axios.post('/api/plan-market/shuadan/page/delete', data)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('删除成功');
              this.getlist();
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //获取
      getlist: function() {
        axios.get('/api/plan-market/shuadan/pages?page='+this.page+'&page_size='+this.pagesize+'&source='+this.source2)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.total = response.data.data.total
              this.list = response.data.data.data
              for(let i in this.list){

                if(this.list[i].status == 1){
                  this.list[i].status = true
                }
                if(this.list[i].status == 0){
                  this.list[i].status = false
                }
              }
              this.loading = false
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //添加供应商先搜索
      search: function() {
        axios.get('/api/gth/order-pages?equal=1&fetch_code='+encodeURIComponent(this.fetch_code))
        	.then(response => {
        		if(response.data.msg.code == 0){
              if(response.data.data.data == ''){
                this.result = "没搜索到商品"
              }else{
                this.result = response.data.data.data[0].title
                this.all.page_id = response.data.data.data[0].id
              }
        		}else{
        			if(response.data.msg.code == 50401){this.$router.push({ path: "/login" }); return false}
        			this.$message.error(response.data.msg.info);
        		}
        	})
      },
      //点击添加
      loggo:function() {
        // let data = {}
        // // data.id = '1'

        // data.source = this.source
        // data.page_id = this.page_id

        axios.post('/api/plan-market/shuadan/page/config', this.all)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.log = false
              this.getlist();
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .index {


        .title {
          border-bottom: 1px #EAEAEA solid;
          line-height: 45px;
          padding-left: 30px;
          font-size: 16px;
          background: #F9F9F9;
          color: #727272
        }

        .add {
          padding: 20px 30px
        }

        .list {
          display: flex;
          text-align: center;
          color: #727272;
          line-height: 45px;
          margin: 0 20px;
          border: 1px #EAEAEA solid;
          margin-top: -1px;

          .th {
            flex: 1;
            background: #F9F9F9;
            font-size: 14px;
            border-right: 1px #EAEAEA solid;
          }

          .td {
            flex: 1;
            font-size: 14px;
            border-right: 1px #EAEAEA solid;
          }
        }

        .el-pagination {
          text-align: right;
          margin: 20px 0
        }


    .result {
      margin-top: 20px;
    }
  }
</style>
